package mt.demo.web.controller.user;

/**
 * Created by watson on 2015/7/22.
 */
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@Controller
public class UserController {
    @RequestMapping(value = "/uploadPage")
    @ResponseBody
    public String updatePage() {
        return "uploadPage";
    }


    @RequestMapping(value = "/upload")
    public String updateThumb(@RequestParam("name") String name,
                              @RequestParam("file") MultipartFile file) throws Exception {
        if (!file.isEmpty()) {
            file.transferTo(new File("d:/temp/" + file.getOriginalFilename()));
            return "redirect:success.html";
        } else {
            return "redirect:fail.html";
        }
    }
}
